﻿using System;
using System.Globalization;
using DslModeling=global::Microsoft.VisualStudio.Modeling;
using DslDiagrams=global::Microsoft.VisualStudio.Modeling.Diagrams;
using DslValidation=global::Microsoft.VisualStudio.Modeling.Validation;

namespace Salamanca.Saml
{

    partial class QuestionState:
        INamedElement
    {
        //partial class DataNamePropertyHandler
        //{
        //    protected override void OnValueChanging(QuestionState element, string oldValue, string newValue)
        //    {
        //        if (!element.Store.InUndoRedoOrRollback)
        //            if (string.IsNullOrEmpty(newValue))
        //                throw new ArgumentOutOfRangeException("DataName", Resources.SR.NameCannotBeNull);

        //        base.OnValueChanging(element, oldValue, newValue);
        //    }
        //}

        /// <summary>Ensures that the data name is valid.</summary>
        [DslValidation.ValidationMethod(DslValidation.ValidationCategories.Menu | DslValidation.ValidationCategories.Open | DslValidation.ValidationCategories.Save)]
        private void ValidateDataName(DslValidation.ValidationContext context)
        {
            if (!ActivityModel.Data.Attributes.Exists(da => string.Compare(da.Name, DataName, false, CultureInfo.InvariantCulture)==0))
            {
                context.LogError(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.SR.NoDataFoundWithName,
                        DataName
                    ),
                    "SAML03",
                    new DslModeling.ModelElement[] { this }
                );
            }
        }
    }
}
